template <class T,class U>
struct Typelist
{
	typedef T Head;
	typedef U Tail;
};

class NullType;
struct EmptyType{};

#define TYPELIST_1(T1) Typelist< T1,NullType >
#define TYPELIST_2(T1,T2) Typelist< T1,TYPELIST_1(T2) >
#define TYPELIST_3(T1,T2,T3) Typelist< T1,TYPELIST_2(T2,T3) >
#define TYPELIST_4(T1,T2,T3,T4) Typelist< T1,TYPELIST_3(T2,T3,T4) >


// len
template <class TList> 
struct Length 
{};
template <> 
struct Length< NullType >
{
	enum { value = 0 };
};
template <class T,class U>
struct Length< Typelist<T,U> >
{
	enum { value = 1+Length<U>::value };
};

// typeat
// TypeAt 真正模版类
template <class TList,int>
struct TypeAt
{};
// TypeAt 模版类的偏特化
template <class Head, class Tail>
struct TypeAt< Typelist<Head,Tail>, 0 >
{
	typedef Head Result;
};
// TypeAt 模版类的偏特化
template <class Head, class Tail,int i>
struct TypeAt< Typelist< Head, Tail>, i >
{
	typedef typename TypeAt< Tail, i-1>::Result Result;
};

// indexof
template <class Tail, class T>
struct Indexof/*< Typelist< T,Tail >, T >*/
{};
template <class T>
struct Indexof< NullType, T >
{
	enum { value = -1 };
};
template <class Head, class Tail, class T>
struct Indexof< Typelist< Head, Tail >, T>
{
	enum { value=Indexof<Tail,T>::value+1 };
};

#include <iostream>
using namespace std;
void print()
{
	cout << endl;
}
template <typename T> 
void print(const T& t)
{
	cout << t << endl;
}
template <typename First,typename ... Rest>
void print(const First& first, const Rest& ... rest)
{
	cout << first << ",,";
	print(rest...);
}

